<template>
  <a-modal
    :zIndex='zIndex'
    :title="$t('按条件添加')"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :okText="$t('保存')"
    @cancel="handleCancel"
    :cancelText="$t('关闭')"
    v-drag
  >
    <a-spin :spinning="confirmLoading">
      <a-form class="batchForm" :model="dataForm">
        <a-form-item style="margin-bottom: 10px" :label="$t('商品')" :labelCol="{ span: 1 }" :wrapperCol="{ span: 20 }">
          <a-select
            showSearch
            v-model="dataForm.goodsId"
            :placeholder="$t('请输入商品编码/名称/条码')"
            style="width: 270px"
            :defaultActiveFirstOption="false"
            :showArrow="false"
            :filterOption="false"
            @search="handleSearch"
            @change="handleChange"
          >
            <a-select-option v-for="d in goodsList" :key="d.id">{{ d.name }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { getAction } from '@/api/manage'

export default {
  name: 'AddGoodsModal',
  data() {
    return {
      zIndex:1002,
      width: 600,
      visible: false,
      model: {},
      confirmLoading: false,
      dataForm: {
        goodsId: '',
      },
      treeData: [],
      allChildKind: [],
      goodsList:[],
      value:'',
    }
  },
  methods: {
    edit(value) {
      this.visible = true
      this.value = value
      this.dataForm.goodsId = ''
      this.getList()
    },
    handleSearch(value){
      this.getList(value)
    },
    handleChange(value){
      this.getList(value)
    },
    getList(value){
      let that = this
      let querydata = {}
      querydata.pageNo = 1
      querydata.pageSize = 10
      querydata.form = "1,2,3,4,5,8"//会员充币和优惠券形态卖品不显示
      querydata.goodsInfo = value
      getAction('/goods/bisGoodsInfor/list', querydata).then(res=>{
        if(res.success){
          that.goodsList = res.result.records
        }
      })
    },
    handleOk() {
      this.$emit('ok', this.dataForm.goodsId,this.value)
      this.close()
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.visible = false
    },
  },
}
</script>
<style>
.batchForm .ant-form-item-label {
  width: 30%;
}
.batchForm .ant-form-item-control-wrapper {
  width: 62.5%;
}
</style>